package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account")
@SuppressWarnings({"all"})
public class RechargeInfoApiController {

	@Autowired
	private RechargeInfoService rechargeInfoService;


	/**
	 * 根据充值订单编号查询充值信息
	 * @param orderNo
	 * @return
	 */
	@Operation(summary = "根据充值订单编号查询充值信息")
	@GetMapping("/rechargeInfo/getRechargeInfo/{orderNo}")
	public Result<RechargeInfo> getRechargeInfo(@PathVariable String orderNo){
		RechargeInfo rechargeInfo = rechargeInfoService.getRechargeInfo(orderNo);
		return Result.ok(rechargeInfo);
	}


	/**
	 * 保存充值
	 * @param rechargeInfoVo
	 * @return {orderNo:"充值订单编号"}
	 */
	@GuiGuLogin
	@Operation(summary = "保存充值")
	@PostMapping("/rechargeInfo/submitRecharge")
	public Result<Map<String, String>> submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo){
		Map<String, String> map = rechargeInfoService.submitRecharge(rechargeInfoVo);
		return Result.ok(map);
	}


	/**
	 * 	微信支付成功后，处理充值业务
	 * @param orderNo
	 * @return
	 */
	@Operation(summary = "微信支付成功后，处理充值业务")
	@GetMapping("/rechargeInfo/rechargePaySuccess/{orderNo}")
	public Result rechargePaySuccess(@PathVariable String orderNo){
		rechargeInfoService.rechargePaySuccess(orderNo);
		return Result.ok();
	}
}

